package com.one.monitoring.utils;

import lombok.extern.slf4j.Slf4j;

import java.sql.*;

/**
 * @author lxh
 * @description mysql测试连接
 * @time 2023/11/17 14:04
 **/
@Slf4j
public class MysqlTestUtils {

    public static Integer testMysql(){
        String driver = "com.mysql.cj.jdbc.Driver";
        String url = "jdbc:mysql://16.162.198.48:3306/onepay-admin";
        //String url = "jdbc:mysql://119.45.186.192:3306/earn10";
        Statement stmt = null;
        ResultSet res = null;
        Connection conn = null;
        String testSql = "SELECT 1 FROM DUAL";
        try {
            Class.forName(driver);
            conn = DriverManager.getConnection(url, "root", "dTi64O28qT");
            //conn = DriverManager.getConnection(url, "root", "cx123465");
            stmt = conn.createStatement();
            res = stmt.executeQuery(testSql);
            if (res.next()) {
                log.info("mysql连接成功！");
            }
            conn.close();
            return 1;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            log.info("ClassNotFoundException");
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            log.info("SQLException:{}",e.getMessage());
        }
        return 2;
    }

    public static void main(String[] args) {
        Integer integer = testMysql();
        System.out.println(integer);
    }
}
